package com.campus.common.mapper;

import com.campus.common.domain.order.Order;
import com.campus.common.domain.order.OrderItem;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert(" insert into `order`( order_id , user_id, price, gmt_create, gmt_modified) values (#{orderId}, #{userId}, #{price}, " +
            "#{gmtCreate}, #{gmtModified})")
    int insertOrder(Order order);

    @Insert("insert into `order_item`( item_id ,order_id, product_id, amount, price, sum_price) " +
            "values (#{itemId}, #{orderId}, #{productId}, #{amount}, #{price}, #{sumPrice})")
    int insertOrderItem(OrderItem orderItem);

    @Update("update `order` set is_pay = 1 , gmt_modified = #{updateTime} where order_id = #{orderId}")
    int orderPay(Long orderId, LocalDateTime updateTime);

    @Delete("update `order` set is_delete = 1 , gmt_modified = #{updateTime} where order_id = #{orderId}")
    int orderDelete(Long orderId, LocalDateTime updateTime);

    @Select("SELECT * from `order` where is_delete != 1 and user_id = #{userId}")
    List<Order> selectAllOrder(Long userId);

    @Select("SELECT * from order_item where order_id = #{orderId}")
    List<OrderItem> selectAllItem(Long orderId);
}

